package com.chen.springboot.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.springboot.entity.ItemParams;
import com.chen.springboot.mapper.ItemParamsMapper;
import com.chen.springboot.service.ItemParamsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ItemParamsServiceImpl extends ServiceImpl<ItemParamsMapper, ItemParams> implements ItemParamsService {
    
    @Override
    public ItemParams getByItemId(Long itemId) {
        QueryWrapper<ItemParams> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("item_id", itemId);
        return this.getOne(queryWrapper);
    }
    
    @Override
    public List<String> getDistinctHotSeries() {
        QueryWrapper<ItemParams> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("DISTINCT hot_series");
        queryWrapper.isNotNull("hot_series");
        queryWrapper.ne("hot_series", "");
        List<ItemParams> list = this.list(queryWrapper);
        return list.stream()
                .map(ItemParams::getHotSeries)
                .distinct()
                .collect(Collectors.toList());
    }
}

